package cn.guozeyiblog.client;

import cn.guozeyiblog.dbhelper.DBHelper;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.preference.EditTextPreference;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceChangeListener;
import android.preference.PreferenceActivity;
import android.util.Log;
import android.view.KeyEvent;

public class SettingActivity extends PreferenceActivity {
	private EditTextPreference editpreference;
	@SuppressWarnings("deprecation")
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		addPreferencesFromResource(R.xml.setting);
		editpreference = (EditTextPreference) findPreference("blogurl");
		editpreference.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
			
			@Override
			public boolean onPreferenceChange(Preference preference, Object newValue) {
				// TODO Auto-generated method stub
				SQLiteDatabase db = new DBHelper(getApplicationContext(), "Detail.db").getWritableDatabase();
				String delete_article = "delete from article where 1=1";
				db.execSQL(delete_article);
				String delete_link = "delete from link where 1=1";
				db.execSQL(delete_link);
				String delete_wechat = "delete from wechat where 1=1";
				db.execSQL(delete_wechat);
				String delete_cate = "delete from cate where 1=1";
				db.execSQL(delete_cate);
				Log.v("setting---weburl", (String)newValue);
				return true;
			}
		});
	}
	
	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		// TODO Auto-generated method stub
		return super.onKeyDown(keyCode, event);
	}
	
	
}
